from django.utils.translation import ugettext as _

from rating.managers import ModelRatedManager
from django.db import models

class AlreadyRegistered(Exception):
    """
    An attempt was made to register a model more than once.
    """
    pass

registry = []

def register(model, calculator, rating_field='rating', rating_manager='rated'):
    if model in registry:
        raise AlreadyRegistered(
            _('The model %s has already been registered.') % model.__name__)
    registry.append(model)
    setattr(model, rating_field, models.FloatField())